package lanqiao14;
// 太难
import java.util.Scanner;

public class F {
	private static int N;
	private static int[] nums;
	private static int min = 2147483647;
	private static int[][] res;
	private static int count = 0;
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		N = scan.nextInt();
		nums = new int[N];
		for (int i = 0; i < N; i++) {
			nums[i] = scan.nextInt();
		}
		sort();// 将数组 nums 从小到大排序
		res = new int[2][(int)Math.pow((nums[N - 1] - nums[0]), 2)];
		for (int i = nums[0]; i < nums[N - 1]; i++) {
			int newMin = 0;
			for (int j = 0; j < N; j++) {
				newMin += Math.abs(nums[j] - i);
			}
			min = Math.min(min, newMin);
		}
		find();
		for (int i = 0; i < count; i++) {
			int newMin = 0;
			for (int j = 0; j < N; j++) {
				newMin += Math.min(Math.abs(nums[j] - res[0][i]), Math.abs(nums[j] - res[1][i]));
			}
			min = Math.min(min, newMin);
		}
		System.out.println(min);
		scan.close();
	}

	// 将 nums 数组排序
	private static void sort() {
		for (int i = 1; i < N; i++) {
			int n = nums[i];
			for (int j = i - 1; j >= 0; j--) {
				if (nums[j] > n) {
					nums[j + 1] = nums[j];
					continue;
				}
				nums[j + 1] = n;
				break;
			}
		}
	}
	
	// 找出所有可能得最终结果
	private static void find() {
		for (int i = nums[0]; i <= nums[N - 1]; i++) {
			for (int j = i + 1; j <= Math.min(nums[N - 1], i * 2 - 1); j++) {
				res[0][count] = i;
				res[1][count] = j;
				count++;
			}
		}
	}
}
 


